package com.innoking.docsys.utils;

import com.alibaba.fastjson.JSONObject;

/**
 * @version V1.0
 * @Title:json转后台接收参数Util
 * @Description:
 * @author: sunq
 * @date: 2018\7\9 0009 11:58
 */
public class JsonToOtherUtil {

    /**
     * 将body字符参数转为参数实体对象
     * @param data
     * @param obj
     * @return
     */
    public static OtherPojo rtOtherPojo(String data,Object obj){
        JSONObject jsonObject=JSONObject.parseObject(data);
        OtherPojo otherPojo = new OtherPojo();
        otherPojo.setToken(jsonObject.getString("token"));
        otherPojo.setDeviceId(jsonObject.getString("deviceId"));
        if(obj!=null){
            String objStr = jsonObject.getString("obj");
            if(StringUtil.isNotEmpty(objStr)){
                Object cls=JSONObject.parseObject(objStr, obj.getClass());
                otherPojo.setObj(cls);
            }
        }
        otherPojo.setPage(jsonObject.getIntValue("page"));
        otherPojo.setMsg(jsonObject.getString("msg"));
        return otherPojo;
    }
}
